package action.business.order;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import service.BusinessOrderService;
import vo.OrderListVO;
import vo.OrderVO;

public class SearchAllOrderAction implements SessionAware{
	
	private BusinessOrderService businessOrderService;
	private String member_id;
	private ArrayList<OrderVO> orderVOList;
	private int totalSum=0;
	private Map<String, Object> session;
	
	public BusinessOrderService getBusinessOrderService() {
		return businessOrderService;
	}
	public void setBusinessOrderService(BusinessOrderService businessOrderService) {
		this.businessOrderService = businessOrderService;
	}
	public String getMember_id() {
		return member_id;
	}
	public void setMember_id(String memberId) {
		member_id = memberId;
	}
	public ArrayList<OrderVO> getOrderVOList() {
		return orderVOList;
	}
	public void setOrderVOList(ArrayList<OrderVO> orderVOList) {
		this.orderVOList = orderVOList;
	}
	public int getTotalSum() {
		return totalSum;
	}
	public void setTotalSum(int totalSum) {
		this.totalSum = totalSum;
	}
		
	@Override
	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.session = session;
	}
	
	
	public String execute(){
		String member =(String) session.get("member_id");
		if(member != null){
			setMember_id(member);
		}
		try {
			ArrayList<String> orderIds = businessOrderService.selectOrderId(member_id);
			orderVOList = businessOrderService.selectOrderVO(orderIds, member_id);
			for(OrderVO ovo : orderVOList){
				for(OrderListVO list : ovo.getList()){
					totalSum = totalSum + list.getTotalPrice();
				}
				ovo.setSumprice(totalSum);
				totalSum = 0;
			}
			System.out.println("action : "+orderVOList);
		} catch (SQLException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return "success";
	}
}
